
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/14/2011 23:03:13
-- Generated from EDMX file: C:\Users\Paul\Documents\Visual Studio 2010\Projects\SimpleForum\SimpleForum\Models\DatabaseContextContainer.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SimpleForum];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CategoryForum]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Forums] DROP CONSTRAINT [FK_CategoryForum];
GO
IF OBJECT_ID(N'[dbo].[FK_UserForum]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Forums] DROP CONSTRAINT [FK_UserForum];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_CategoryUser];
GO
IF OBJECT_ID(N'[dbo].[FK_PostUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_PostUser];
GO
IF OBJECT_ID(N'[dbo].[FK_ForumForum]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Forums] DROP CONSTRAINT [FK_ForumForum];
GO
IF OBJECT_ID(N'[dbo].[FK_ThreadUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Threads] DROP CONSTRAINT [FK_ThreadUser];
GO
IF OBJECT_ID(N'[dbo].[FK_PostThread]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Posts] DROP CONSTRAINT [FK_PostThread];
GO
IF OBJECT_ID(N'[dbo].[FK_ForumThread]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Threads] DROP CONSTRAINT [FK_ForumThread];
GO
IF OBJECT_ID(N'[dbo].[FK_ReputationUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reputations] DROP CONSTRAINT [FK_ReputationUser];
GO
IF OBJECT_ID(N'[dbo].[FK_AchievementUserAchievement]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserAchievements] DROP CONSTRAINT [FK_AchievementUserAchievement];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAchievementUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserAchievements] DROP CONSTRAINT [FK_UserAchievementUser];
GO
IF OBJECT_ID(N'[dbo].[FK_PostRatingPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostRatings] DROP CONSTRAINT [FK_PostRatingPost];
GO
IF OBJECT_ID(N'[dbo].[FK_PostRatingRating]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostRatings] DROP CONSTRAINT [FK_PostRatingRating];
GO
IF OBJECT_ID(N'[dbo].[FK_PostRatingUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostRatings] DROP CONSTRAINT [FK_PostRatingUser];
GO
IF OBJECT_ID(N'[dbo].[FK_PostReportReportReasons]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostReports] DROP CONSTRAINT [FK_PostReportReportReasons];
GO
IF OBJECT_ID(N'[dbo].[FK_PostReportUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostReports] DROP CONSTRAINT [FK_PostReportUser];
GO
IF OBJECT_ID(N'[dbo].[FK_PostReportPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostReports] DROP CONSTRAINT [FK_PostReportPost];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificationUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notifications] DROP CONSTRAINT [FK_NotificationUser];
GO
IF OBJECT_ID(N'[dbo].[FK_TagThread_Tag]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TagThread] DROP CONSTRAINT [FK_TagThread_Tag];
GO
IF OBJECT_ID(N'[dbo].[FK_TagThread_Thread]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TagThread] DROP CONSTRAINT [FK_TagThread_Thread];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Categories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Categories];
GO
IF OBJECT_ID(N'[dbo].[Forums]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Forums];
GO
IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Users];
GO
IF OBJECT_ID(N'[dbo].[Posts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Posts];
GO
IF OBJECT_ID(N'[dbo].[Threads]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Threads];
GO
IF OBJECT_ID(N'[dbo].[Tags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tags];
GO
IF OBJECT_ID(N'[dbo].[Configurations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Configurations];
GO
IF OBJECT_ID(N'[dbo].[Reputations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reputations];
GO
IF OBJECT_ID(N'[dbo].[Achievements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Achievements];
GO
IF OBJECT_ID(N'[dbo].[UserAchievements]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserAchievements];
GO
IF OBJECT_ID(N'[dbo].[PostRatings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PostRatings];
GO
IF OBJECT_ID(N'[dbo].[Ratings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ratings];
GO
IF OBJECT_ID(N'[dbo].[ReportReasons]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ReportReasons];
GO
IF OBJECT_ID(N'[dbo].[PostReports]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PostReports];
GO
IF OBJECT_ID(N'[dbo].[Notifications]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notifications];
GO
IF OBJECT_ID(N'[dbo].[TagThread]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TagThread];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Categories'
CREATE TABLE [dbo].[Categories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [CreatorId] int  NOT NULL
);
GO

-- Creating table 'Forums'
CREATE TABLE [dbo].[Forums] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [CategoryId] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [CreatorId] int  NOT NULL,
    [ParentForumId] int  NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[Users] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserName] varchar(100)  NOT NULL,
    [PasswordHash] varchar(40)  NOT NULL,
    [PasswordSalt] char(5)  NOT NULL,
    [Email] varchar(100)  NOT NULL,
    [Enabled] bit  NOT NULL,
    [DateCreated] datetime  NOT NULL,
    [DateLastLogin] datetime  NULL,
    [DateLastActivity] datetime  NULL,
    [DateLastPasswordChange] datetime  NOT NULL,
    [FacebookUsername] nvarchar(max)  NULL,
    [TwitterUsername] nvarchar(max)  NULL,
    [AvatarFilename] nvarchar(max)  NULL,
    [Bio] nvarchar(max)  NULL
);
GO

-- Creating table 'Posts'
CREATE TABLE [dbo].[Posts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [CreatorId] int  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [ThreadId] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [LastEditDate] datetime  NULL,
    [IsSpam] bit  NOT NULL
);
GO

-- Creating table 'Threads'
CREATE TABLE [dbo].[Threads] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [CreatorId] int  NOT NULL,
    [ForumId] int  NOT NULL,
    [CreatedDate] datetime  NOT NULL,
    [Views] int  NOT NULL
);
GO

-- Creating table 'Tags'
CREATE TABLE [dbo].[Tags] (
    [Name] nvarchar(50)  NOT NULL,
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'Configurations'
CREATE TABLE [dbo].[Configurations] (
    [Value] nvarchar(max)  NOT NULL,
    [Key] nvarchar(max)  NOT NULL,
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Reputations'
CREATE TABLE [dbo].[Reputations] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [ReputationEarned] int  NOT NULL,
    [ReputationType] nvarchar(max)  NOT NULL,
    [URL] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Achievements'
CREATE TABLE [dbo].[Achievements] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'UserAchievements'
CREATE TABLE [dbo].[UserAchievements] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [AchievementName] nvarchar(50)  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'PostRatings'
CREATE TABLE [dbo].[PostRatings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RatingName] nvarchar(50)  NOT NULL,
    [PostId] int  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'Ratings'
CREATE TABLE [dbo].[Ratings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'ReportReasons'
CREATE TABLE [dbo].[ReportReasons] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Reason] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'PostReports'
CREATE TABLE [dbo].[PostReports] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ReportReason] nvarchar(50)  NOT NULL,
    [PostId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [DateReported] datetime  NOT NULL,
    [Reason] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Notifications'
CREATE TABLE [dbo].[Notifications] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [Message] nvarchar(max)  NOT NULL,
    [DateReceived] datetime  NOT NULL
);
GO

-- Creating table 'TagThread'
CREATE TABLE [dbo].[TagThread] (
    [Tags_Id] int  NOT NULL,
    [Threads_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [PK_Categories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Forums'
ALTER TABLE [dbo].[Forums]
ADD CONSTRAINT [PK_Forums]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Users'
ALTER TABLE [dbo].[Users]
ADD CONSTRAINT [PK_Users]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [PK_Posts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [PK_Threads]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [PK_Tags]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Configurations'
ALTER TABLE [dbo].[Configurations]
ADD CONSTRAINT [PK_Configurations]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Reputations'
ALTER TABLE [dbo].[Reputations]
ADD CONSTRAINT [PK_Reputations]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Name] in table 'Achievements'
ALTER TABLE [dbo].[Achievements]
ADD CONSTRAINT [PK_Achievements]
    PRIMARY KEY CLUSTERED ([Name] ASC);
GO

-- Creating primary key on [Id] in table 'UserAchievements'
ALTER TABLE [dbo].[UserAchievements]
ADD CONSTRAINT [PK_UserAchievements]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PostRatings'
ALTER TABLE [dbo].[PostRatings]
ADD CONSTRAINT [PK_PostRatings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Name] in table 'Ratings'
ALTER TABLE [dbo].[Ratings]
ADD CONSTRAINT [PK_Ratings]
    PRIMARY KEY CLUSTERED ([Name] ASC);
GO

-- Creating primary key on [Reason] in table 'ReportReasons'
ALTER TABLE [dbo].[ReportReasons]
ADD CONSTRAINT [PK_ReportReasons]
    PRIMARY KEY CLUSTERED ([Reason] ASC);
GO

-- Creating primary key on [Id] in table 'PostReports'
ALTER TABLE [dbo].[PostReports]
ADD CONSTRAINT [PK_PostReports]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [PK_Notifications]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Tags_Id], [Threads_Id] in table 'TagThread'
ALTER TABLE [dbo].[TagThread]
ADD CONSTRAINT [PK_TagThread]
    PRIMARY KEY NONCLUSTERED ([Tags_Id], [Threads_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CategoryId] in table 'Forums'
ALTER TABLE [dbo].[Forums]
ADD CONSTRAINT [FK_CategoryForum]
    FOREIGN KEY ([CategoryId])
    REFERENCES [dbo].[Categories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryForum'
CREATE INDEX [IX_FK_CategoryForum]
ON [dbo].[Forums]
    ([CategoryId]);
GO

-- Creating foreign key on [CreatorId] in table 'Forums'
ALTER TABLE [dbo].[Forums]
ADD CONSTRAINT [FK_UserForum]
    FOREIGN KEY ([CreatorId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserForum'
CREATE INDEX [IX_FK_UserForum]
ON [dbo].[Forums]
    ([CreatorId]);
GO

-- Creating foreign key on [CreatorId] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [FK_CategoryUser]
    FOREIGN KEY ([CreatorId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryUser'
CREATE INDEX [IX_FK_CategoryUser]
ON [dbo].[Categories]
    ([CreatorId]);
GO

-- Creating foreign key on [CreatorId] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_PostUser]
    FOREIGN KEY ([CreatorId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostUser'
CREATE INDEX [IX_FK_PostUser]
ON [dbo].[Posts]
    ([CreatorId]);
GO

-- Creating foreign key on [ParentForumId] in table 'Forums'
ALTER TABLE [dbo].[Forums]
ADD CONSTRAINT [FK_ForumForum]
    FOREIGN KEY ([ParentForumId])
    REFERENCES [dbo].[Forums]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ForumForum'
CREATE INDEX [IX_FK_ForumForum]
ON [dbo].[Forums]
    ([ParentForumId]);
GO

-- Creating foreign key on [CreatorId] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [FK_ThreadUser]
    FOREIGN KEY ([CreatorId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ThreadUser'
CREATE INDEX [IX_FK_ThreadUser]
ON [dbo].[Threads]
    ([CreatorId]);
GO

-- Creating foreign key on [ThreadId] in table 'Posts'
ALTER TABLE [dbo].[Posts]
ADD CONSTRAINT [FK_PostThread]
    FOREIGN KEY ([ThreadId])
    REFERENCES [dbo].[Threads]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostThread'
CREATE INDEX [IX_FK_PostThread]
ON [dbo].[Posts]
    ([ThreadId]);
GO

-- Creating foreign key on [ForumId] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [FK_ForumThread]
    FOREIGN KEY ([ForumId])
    REFERENCES [dbo].[Forums]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ForumThread'
CREATE INDEX [IX_FK_ForumThread]
ON [dbo].[Threads]
    ([ForumId]);
GO

-- Creating foreign key on [UserId] in table 'Reputations'
ALTER TABLE [dbo].[Reputations]
ADD CONSTRAINT [FK_ReputationUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ReputationUser'
CREATE INDEX [IX_FK_ReputationUser]
ON [dbo].[Reputations]
    ([UserId]);
GO

-- Creating foreign key on [AchievementName] in table 'UserAchievements'
ALTER TABLE [dbo].[UserAchievements]
ADD CONSTRAINT [FK_AchievementUserAchievement]
    FOREIGN KEY ([AchievementName])
    REFERENCES [dbo].[Achievements]
        ([Name])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AchievementUserAchievement'
CREATE INDEX [IX_FK_AchievementUserAchievement]
ON [dbo].[UserAchievements]
    ([AchievementName]);
GO

-- Creating foreign key on [UserId] in table 'UserAchievements'
ALTER TABLE [dbo].[UserAchievements]
ADD CONSTRAINT [FK_UserAchievementUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAchievementUser'
CREATE INDEX [IX_FK_UserAchievementUser]
ON [dbo].[UserAchievements]
    ([UserId]);
GO

-- Creating foreign key on [PostId] in table 'PostRatings'
ALTER TABLE [dbo].[PostRatings]
ADD CONSTRAINT [FK_PostRatingPost]
    FOREIGN KEY ([PostId])
    REFERENCES [dbo].[Posts]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostRatingPost'
CREATE INDEX [IX_FK_PostRatingPost]
ON [dbo].[PostRatings]
    ([PostId]);
GO

-- Creating foreign key on [RatingName] in table 'PostRatings'
ALTER TABLE [dbo].[PostRatings]
ADD CONSTRAINT [FK_PostRatingRating]
    FOREIGN KEY ([RatingName])
    REFERENCES [dbo].[Ratings]
        ([Name])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostRatingRating'
CREATE INDEX [IX_FK_PostRatingRating]
ON [dbo].[PostRatings]
    ([RatingName]);
GO

-- Creating foreign key on [UserId] in table 'PostRatings'
ALTER TABLE [dbo].[PostRatings]
ADD CONSTRAINT [FK_PostRatingUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostRatingUser'
CREATE INDEX [IX_FK_PostRatingUser]
ON [dbo].[PostRatings]
    ([UserId]);
GO

-- Creating foreign key on [ReportReason] in table 'PostReports'
ALTER TABLE [dbo].[PostReports]
ADD CONSTRAINT [FK_PostReportReportReasons]
    FOREIGN KEY ([ReportReason])
    REFERENCES [dbo].[ReportReasons]
        ([Reason])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostReportReportReasons'
CREATE INDEX [IX_FK_PostReportReportReasons]
ON [dbo].[PostReports]
    ([ReportReason]);
GO

-- Creating foreign key on [UserId] in table 'PostReports'
ALTER TABLE [dbo].[PostReports]
ADD CONSTRAINT [FK_PostReportUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostReportUser'
CREATE INDEX [IX_FK_PostReportUser]
ON [dbo].[PostReports]
    ([UserId]);
GO

-- Creating foreign key on [PostId] in table 'PostReports'
ALTER TABLE [dbo].[PostReports]
ADD CONSTRAINT [FK_PostReportPost]
    FOREIGN KEY ([PostId])
    REFERENCES [dbo].[Posts]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PostReportPost'
CREATE INDEX [IX_FK_PostReportPost]
ON [dbo].[PostReports]
    ([PostId]);
GO

-- Creating foreign key on [UserId] in table 'Notifications'
ALTER TABLE [dbo].[Notifications]
ADD CONSTRAINT [FK_NotificationUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[Users]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificationUser'
CREATE INDEX [IX_FK_NotificationUser]
ON [dbo].[Notifications]
    ([UserId]);
GO

-- Creating foreign key on [Tags_Id] in table 'TagThread'
ALTER TABLE [dbo].[TagThread]
ADD CONSTRAINT [FK_TagThread_Tag]
    FOREIGN KEY ([Tags_Id])
    REFERENCES [dbo].[Tags]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Threads_Id] in table 'TagThread'
ALTER TABLE [dbo].[TagThread]
ADD CONSTRAINT [FK_TagThread_Thread]
    FOREIGN KEY ([Threads_Id])
    REFERENCES [dbo].[Threads]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TagThread_Thread'
CREATE INDEX [IX_FK_TagThread_Thread]
ON [dbo].[TagThread]
    ([Threads_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------